package com.xy.controller;

import java.util.List;
import java.util.UUID;

import com.xy.common.ResourceNotFoundException;
import com.xy.entity.UserProfilesEntity;
import com.xy.service.UserProfileService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * .
 * <p>
 *
 * @author <a href="mailto:shunshun.lss@alibaba-inc.com">shunshun.lss</a>
 * @version 1.0.0
 * @since 2024-10-14
 */

@RestController
@RequestMapping("/api/user-profiles")
public class UserProfilesController {

    @Resource
    UserProfileService userProfileService;

    @PostMapping
    public UserProfilesEntity createUserProfile(@RequestBody UserProfilesEntity userProfile) {
        userProfile.setCreateBy(UUID.randomUUID());
        return userProfileService.createUserProfile(userProfile);
    }

    @GetMapping
    public List<UserProfilesEntity> getAllUserProfiles() {
        return userProfileService.getAllUserProfiles();
    }

    @GetMapping("/{id}")
    public ResponseEntity<UserProfilesEntity> getUserProfileById(@PathVariable UUID id) {
        UserProfilesEntity userProfile = userProfileService.getUserProfileById(id)
                .orElseThrow(() -> new ResourceNotFoundException("User profile not found"));
        return ResponseEntity.ok(userProfile);
    }

    @PutMapping("/{id}")
    public ResponseEntity<UserProfilesEntity> updateUserProfile(@PathVariable UUID id, @RequestBody UserProfilesEntity userProfile) {
        userProfile.setUpdateBy(UUID.randomUUID());
        UserProfilesEntity updatedUserProfile = userProfileService.updateUserProfile(id, userProfile);
        return ResponseEntity.ok(updatedUserProfile);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteUserProfile(@PathVariable UUID id) {
        userProfileService.deleteUserprofile(id);
        return ResponseEntity.noContent().build();
    }

}